package cn.com.cym.gamezao.web.demo;

import cn.com.cym.gamezao.annotation.AuthToken;
import cn.com.cym.gamezao.base.BaseController;
import cn.com.cym.gamezao.base.BaseService;
import cn.com.cym.gamezao.base.ResultResponse;
import cn.com.cym.gamezao.base.SearchPage;
import cn.com.cym.gamezao.entity.demo.Parent;
import cn.com.cym.gamezao.service.demo.ParentService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "x-父类控制")
@RestController
@RequestMapping(value = "parent")
@AuthToken(rule = "demo.parent")
public class ParentController extends BaseController<Parent> {

    final ParentService thisService;

    public ParentController(ParentService parentService){
        this.thisService=parentService;
    }

    @ApiImplicitParam(name = "code", value = "code", required = true,dataType = "String")
    @ApiOperation(value = "按照编码获取")
    @ApiOperationSupport(order = 1, author = "mr.chen")
    @GetMapping("/code/{code}")
    public ResponseEntity<?> getByCode(@PathVariable String code){
        Parent parent = this.thisService.getByCode(code);
        return ResponseEntity.ok(parent);
    }


    @ApiImplicitParam(name = "parent", value = "parent", required = true,dataType = "Parent")
    @ApiOperation(value = "新建父类")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PostMapping()
    @AuthToken(rule = "add")
    public ResponseEntity<?> add(@RequestBody Parent parent){
        final Parent storeParent = this.thisService.save(parent);
        return ResponseEntity.ok(storeParent);
    }


    @ApiImplicitParams({@ApiImplicitParam(name = "code", value = "code",paramType = "path", required = true,dataType = "String"),
            @ApiImplicitParam(name = "parent", value = "parent",paramType = "", required = true,dataType = "Parent")})
    @ApiOperation(value = "更新父类")
    @ApiOperationSupport(order = 3, author = "mr.chen")
    @PutMapping("/{code}")
    @AuthToken(rule = "update")
    public ResponseEntity<?> update(@RequestBody Parent parent,@PathVariable String code){
        final Parent storeParent = this.thisService.updateByCode(parent,code);
        return ResponseEntity.ok(storeParent);
    }

    @Override
    public BaseService<Parent> getService() {
        return this.thisService;
    }

   /* @ApiImplicitParam(name = "id", value = "id",paramType = "path",required = true,dataType = "Long")
    @ApiOperation(value = "删除父类")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @DeleteMapping("/{id}")
    @AuthToken(rule = "delete")
    public ResponseEntity<?> delete(@PathVariable Long id){
        this.thisService.physicalDelete(id);
        return ResponseEntity.ok(new ResultResponse("删除成功", HttpStatus.OK.value()));
    }

    @ApiImplicitParam(name = "searchPage", value = "searchPage", required = true,dataType = "SearchPage")
    @ApiOperation(value = "分页显示page！")
    @ApiOperationSupport(order = 4, author = "mr.chen")
    @PostMapping("/page")
    public ResponseEntity<?> page(@RequestBody SearchPage searchPage){
        Page<?> byPageable = this.thisService.findByPageable(searchPage);
        return ResponseEntity.ok(byPageable);
    }
*/


}
